package com.three.controller;

import com.three.mapper.StudentMapper;
import com.three.pojo.Result;
import com.three.pojo.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RequestMapping("/register")
@RestController
@CrossOrigin
public class Register {

    @Autowired
    private StudentMapper studentMapper;

    @PostMapping
    public Result register(@RequestBody Student student) {
        log.info("日志 POST /register 姓名:" + student.getName() + "学号:" + student.getId()+"班级:" + student.getPassword());
        if (studentMapper.isExist(student.getId()) != null) {
            return Result.fail("该用户已存在");
        }
        int result = studentMapper.insert(student);
        if (result > 0) {
            return Result.success("注册成功");
        }
        return Result.fail("注册失败");
    }
}
